home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
bluebook.zip
/
GRAPHICS.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-05-08
|
24KB
|
894 lines
COMMENT ~
GRAPHICS.ASM -- Graphic Plotting Procedures
From `BLUEBOOK of ASSEMBLY ROUTINES for the IBM PC & XT'
by Christopher L. Morgan
Copyright (C) 1984 by The Waite Group, Inc.
Contents:
---------
CLS -- Clear the screen
GET_COLOR -- Get the color of a point on the med res color screen
GMSG_OUT -- Plot a string
PAINT -- Fill an area with specified color
RCHAR -- Plot a raster character
SCHAR -- Plot a stroke character
SET_BOX -- Fill a rectangular box with specified color
SET_LIN -- Draw a line
SET_PT -- Plot a point
XOR_BOX -- Fill a rectangular box using XOR
XOR_PT -- Plot a point using XOR
>>>>> See GRAPHICS.DOC for complete descriptions of these routines. <<<<<
------------------------------------------------------------------------------
These variables need to be defined in the source code calling the GRAPHICS
routines. See GRAPHICS.DOC. ~
EXTRN CBYTES:BYTE, COLOR:WORD, DELDE:WORD, DELDX:WORD
EXTRN DELDY:WORD, DELP:WORD, DELS:WORD, DELSE:WORD
EXTRN DELSX:WORD, DELSY:WORD, FONT:BYTE, PAINT_STAK:WORD
EXTRN X0:WORD, X1:WORD, X2:WORD, XMAGN:BYTE
EXTRN XMSG:WORD, Y0:WORD, Y1:WORD, Y2:WORD
EXTRN YMAGN:BYTE, YMSG:WORD
;______________________________________________________________________________
;These tables would be better included in the source code calling the
; GRAPHICS routines, and then commented out here. See GRAPHICS.DOC
;
DATAS SEGMENT PUBLIC
CTABLE DW 0003FH,0403FH,0803FH,0C03FH
DW 000CFH,010CFH,020CFH,030CFH
DW 000F3H,004F3H,008F3H,00CF3H
DW 000FCH,001FCH,002FCH,003FCH
PTABLE DW 32 DUP(?) ;A dummy (See GRAPHICS.DOC)
XTABLE DW 0FFC0H,0FFF0H,0FFFCH,0FFFFH
DW 03FC0H,03FF0H,03FFCH,03FFFH
DW 00FC0H,00FF0H,00FFCH,00FFFH
DW 003C0H,003F0H,003FCH,003FFH
DATAS ENDS
;______________________________________________________________________________
;
CODES SEGMENT
PUBLIC CLS,SET_PT,XOR_PT,GET_COLOR,SET_BOX,XOR_BOX
PUBLIC SET_LIN,SCHAR,RCHAR,GMSG_OUT,PAINT
ASSUME CS:CODES,DS:DATAS
;____________________________I/O ROUTINES______________________________________
;Routine to clear the graphics screen
;
CLS PROC FAR
PUSH CX ;Save registers
PUSH AX
;
;Set up the registers
MOV CX,2000H ;Word count of whole screen
MOV AX,0 ;Zero pattern for the screen
MOV DI,AX ;Set starting address
CLD ;Go in forward direction
;
;Clear the screen with a single string operation
REP STOSW ;This clears the screen
;
POP AX ;Restore registers
POP CX
RET
CLS ENDP
;------------------------------------------------------------------------------
;Routine to plot a point on medium resolution color screen
;
SET_PT PROC FAR
PUSH BX ;Save registers
PUSH SI
PUSH AX
;
;Multiply Y-coord by bytes/row & adjust for even/odd lines
MOV AX,DI ;Get Y-coordinate into part
MOV AH,AL ; and into high part
AND AX,01FEH ;Mask off unwanted parts
SAL AX,1 ;Times 4
SAL AX,1 ;Times 8
SAL AX,1 ;Times 16
MOV BX,AX ;Goes into address
AND BH,7 ; without adjustment
SAL AX,1 ;Times 32
SAL AX,1 ;Times 64
ADD BX,AX ;Addr gets Y-coord times 80
;
;Add X-coordinate to address
MOV AX,SI ;Get X-coordinate
SAR AX,1 ;Divide
SAR AX,1 ; by 4
ADD BX,AX ;Here is the address
;
;Compute the rotated mask and color
AND SI,3 ;Just pixel position into index
SAL SI,1 ;Index times 2
SAL SI,1 ;Index times 4
ADD SI,DX ;4 * pixel position + color
SAL SI,1 ;8 * pixel position + 2 * color
MOV AX,CTABLE[SI] ;Look up rotated color & mask
;
;Insert the color into the video byte
AND AL,ES:[BX] ;Get old byte & remove old pixel
OR AL,AH ;Insert new color
MOV ES:[BX],AL ;Put the byte back
;
POP AX ;Restore registers
POP SI
POP BX
RET
SET_PT ENDP
;------------------------------------------------------------------------------
;Routine to XOR a point onto medium resolution color screen
;
XOR_PT PROC FAR
PUSH BX ;Save registers
PUSH SI
PUSH AX
;
;Multiply Y-coord by bytes/row & adjust for even/odd lines
MOV AX,DI ;Get Y-coordinate into part
MOV AH,AL ; and into high part
AND AX,01FEH ;Mask off unwanted parts
SAL AX,1 ;Times 4
SAL AX,1 ;Times 8
SAL AX,1 ;Times 16
MOV BX,AX ;Goes into address
AND BH,7 ; without adjustment
SAL AX,1 ;Times 32
SAL AX,1 ;Times 64
ADD BX,AX ;Addr gets Y-coord times 80
;
;Add X-coordinate to address
MOV AX,SI ;Get X-coordinate
SAR AX,1 ;Divide
SAR AX,1 ; by 4
ADD BX,AX ;Here is the address
;
;Compute the mask for color and use it
AND SI,3 ;Just the bit count into index
SAL SI,1 ;Index times 2
SAL SI,1 ;Index times 4
ADD SI,DX ;4 * pixel position + color
SAL SI,1 ;8 * pixel position + 2 * color
MOV AX,CTABLE[SI] ;Look up rotated color & mask
XOR ES:[BX],AH ;XOR the byte with the color
;
POP AX ;Restore registers
POP SI
POP BX
RET
XOR_PT ENDP
;------------------------------------------------------------------------------
;Routine to return color of a point on med res color screen
;
GET_COLOR PROC FAR
PUSH BX ;Save registers
PUSH CX
;
;Multiply Y-coord by bytes/row & adjust for even/odd lines
MOV AX,DI ;Get Y-coordinate into part
MOV AH,AL ; and into high part
AND AX,01FEH ;Mask off unwanted parts
SAL AX,1 ;Times 4
SAL AX,1 ;Times 8
SAL AX,1 ;Times 16
MOV BX,AX ;Goes into address
AND BH,7 ; without adjustment
SAL AX,1 ;Times 32
SAL AX,1 ;Times 64
ADD BX,AX ;Addr gets Y-coord times 80
;
;Add X-coordinate to address
MOV AX,SI ;Get X-coordinate
SAR AX,1 ;Divide
SAR AX,1 ; by 4
ADD BX,AX ;Here is the address
;
;Compute the position of the pixel in the byte
MOV CX,SI ;Use X-coord to determine count
AND CX,3 ;Just the bit count
INC CX ; plus one
SAL CX,1 ;2 bits/pixel
;
;Get the byte and rotate into place
MOV AL,ES:[BX] ;Get old byte
ROL AL,CL ;Rotate left this many times
AND AX,3 ;Just the pixel color
;
POP CX ;Restore registers
POP BX
RET
GET_COLOR ENDP
;------------------------------------------------------------------------------
;Routine to set & fill a rectangular box
;
SET_BOX PROC FAR
PUSH SI ;Save registers
PUSH DI
PUSH DX
PUSH BX
PUSH CX
PUSH AX
;
;Determine byte position for start
;
;Get Y contribution
MOV AX,Y1 ;Get starting Y-coordinate
MOV AH,AL ;Replicate for odd/even bank
AND AX,01FEH ;Mask off unwanted parts
SAL AX,1 ;Times 4
SAL AX,1 ;Times 8
SAL AX,1 ;Times 16
MOV DI,AX ;Addr gets Y-coord * 16
AND DI,7FFH ;Not the odd/even bit
SAL AX,1 ;Times 32
SAL AX,1 ;Times 64
ADD DI,AX ;Addr gets Y-coord * 80
;
;Add in X contribution
MOV AX,X1 ;Get X-coordinate
SAR AX,1 ;Divide
SAR AX,1 ; by 4
ADD DI,AX ;Beginning of offset
;
;Count for outer loop
MOV CX,Y2 ;Ending Y-coordinate
SUB CX,Y1 ; minus starting Y-coordinate
INC CX ; plus one
;
;Count for inner loop
MOV SI,X2 ;Ending X-coordinate
SAR AX,1 ;Divide
SAR AX,1 ; by 4
MOV AX,X1 ;Starting X-coordinate
SAR AX,1 ;Divide
SAR AX,1 ; by 4
SUB SI,AX ;Take the difference
;Get the color
MOV BX,COLOR ;Get the color
AND BX,3 ;Just between 0 & 3
MOV DL,CBYTES[BX] ;Look up color pattern
;
;Determine mask for start & ending bytes
MOV BX,X1 ;Starting byte
AND BX,3 ;Just the pixel position
SAL BX,1 ;Times 2
SAL BX,1 ;Times 4
MOV AX,X2 ;Ending byte
AND AX,3 ;Just the pixel position
ADD BX,AX ;4 * starting + ending
SAL BX,1 ;8 * starting + 2 * ending
MOV BX,XTABLE[BX] ;Look up the masks
;
;Set up masked color bytes
MOV DH,DL ;Color for left bytes
MOV AH,DL ;Color for middle bytes
AND DX,BX ;Mask left & right color bytes
;
CLD ;Forward
SBOXLOOP:
PUSH CX ;Save count of outer loop
PUSH DI ;Save initial byte position
;
MOV CX,SI